package com.example.icedcap.topeka_fake.activity;

import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.example.icedcap.topeka_fake.R;
import com.example.icedcap.topeka_fake.fragment.SignInFragment;
import com.example.icedcap.topeka_fake.helper.PreferenceHelper;

/**
 * Created by doushuqi on 15-7-11上午10:47.
 * Email:doushuqi0409@gmail.com
 */
public class SignInActivity extends Activity {
    private static final String TAG = SignInActivity.class.getSimpleName();
    private static final String EXTRA_EDIT = "EDIT";

    public static void start(Activity activity, boolean edit, ActivityOptions options){
        Intent starter = new Intent(activity, SignInActivity.class);
        starter.putExtra(EXTRA_EDIT, edit);
        if (null == options) {
            activity.startActivity(starter);
            activity.overridePendingTransition(android.R.anim.slide_in_left,
                    android.R.anim.slide_out_right);
        } else {
            activity.startActivity(starter, options.toBundle());
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_in);
        final boolean edit = isInEditMode();
        if (null == savedInstanceState) {
            Log.e(TAG, TAG);
            getFragmentManager().beginTransaction()
                    .replace(R.id.sign_in_container, SignInFragment.newInstance(edit))
                    .commit();
        }

    }

    @Override
    protected void onStop() {
        super.onStop();
        if (PreferenceHelper.isSignIn(this)) {
            finish();
        }
    }

    private boolean isInEditMode() {
        Intent intent = getIntent();
        boolean edit = false;
        if (null != intent) {
            edit = intent.getBooleanExtra(EXTRA_EDIT, false);
        }
        return edit;
    }
}
